package com.offics.loan.interfaces.controller;

import com.offics.loan.application.dto.loan.LoanProductResponse;
import com.offics.loan.application.service.LoanApplicationService;
import com.offics.loan.infrastructure.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 贷款产品控制器
 */
@Tag(name = "贷款产品", description = "贷款产品相关接口")
@RestController
@RequestMapping("/api/loan-products")
@RequiredArgsConstructor
public class LoanProductController {

    private final LoanApplicationService loanApplicationService;

    /**
     * 获取贷款产品列表
     *
     * @return 贷款产品列表
     */
    @Operation(summary = "获取贷款产品列表", description = "获取贷款产品列表")
    @GetMapping
    public Result<List<LoanProductResponse>> getLoanProductList() {
        List<LoanProductResponse> responses = loanApplicationService.getLoanProductList();
        return Result.success(responses);
    }

    /**
     * 获取贷款产品详情
     *
     * @param id 产品ID
     * @return 贷款产品详情
     */
    @Operation(summary = "获取贷款产品详情", description = "获取贷款产品详情")
    @GetMapping("/{id}")
    public Result<LoanProductResponse> getLoanProductDetail(@PathVariable Long id) {
        LoanProductResponse response = loanApplicationService.getLoanProductDetail(id);
        return Result.success(response);
    }
}
